package com.zhuang.learn.junit;

import org.apache.commons.math3.random.RandomAdaptor;
import org.apache.commons.math3.random.Well1024a;

import java.util.HashSet;
import java.util.Random;

/**
 * Created by zhuanglei on 15/4/9.
 */
public class GenerateNumberImpl implements GenerateNumber {
    private Random random = new Random();


    @Override
    public String generateNoRepeaterNumber(int length) {
        HashSet<String> digitalSet = new HashSet<String>();
        int max=10;
        int min=0;

        while (digitalSet.size() < 4) {
            digitalSet.add(String.valueOf(random.nextInt(max) % (max - min + 1) + min));
        }

        return getDigitalString(digitalSet);
    }

    private String getDigitalString(HashSet<String> digital) {
        String result = "";
        for (Object c : digital.toArray()) {
            result = result + (String) c;
        }
        return result;
    }
}
